package com.bwda.dsrs.filecenter.controller;

import com.bwda.dsrs.filecenter.domain.po.dspdbscanresult.DspDbScanResultPo;
import com.bwda.dsrs.filecenter.domain.condition.dspdbscanresult.DspDbScanResultCondition;
import com.bwda.dsrs.filecenter.domain.form.dspdbscanresult.DspDbScanResultQueryForm;
import com.bwda.dsrs.filecenter.domain.form.dspdbscanresult.DspDbScanResultUpdateForm;
import com.bwda.dsrs.filecenter.domain.form.dspdbscanresult.DspDbScanResultCreateForm;
import com.bwda.dsrs.filecenter.domain.vo.dspdbscanresult.DspDbScanResultVo;
import com.bwda.dsrs.filecenter.service.DspDbScanResultService;
import com.bwda.dsrs.filecenter.domain.exception.BusinessServiceException;
import com.bwda.dsrs.base.centerbase.response.CentreListResponse;
import com.bwda.dsrs.base.centerbase.response.CentreCutPageResponse;
import com.bwda.dsrs.base.centerbase.response.ResponseEntity;
import java.util.List;
import java.util.ArrayList;
import com.bwda.dsrs.base.util.CopyUtil;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
/**
 * @author Administrator
 */
@RestController
@RequestMapping("/dspdbscanresult")
@Api(value = "/dspdbscanresult", tags = "敏感字段扫描结果表")
public class DspDbScanResultController extends BaseController {

	@Autowired
	private DspDbScanResultService dspDbScanResultService;

	@ApiOperation(value = "查询敏感字段扫描结果表",notes = "查询敏感字段扫描结果表",httpMethod = "GET")
	@RequestMapping(value = "/query", method = {RequestMethod.GET, RequestMethod.POST})
	public ResponseEntity<DspDbScanResultVo> query(@ApiParam(value = "id", required = true)@RequestParam Integer scanResultId) throws BusinessServiceException {
		DspDbScanResultPo po = dspDbScanResultService.queryWithValid(scanResultId);
		DspDbScanResultVo vo = CopyUtil.transfer(po, DspDbScanResultVo.class);
		return getSuccessResult(vo);
	}

	@ApiOperation(value = "查询敏感字段扫描结果表数量",notes = "查询敏感字段扫描结果表数量",httpMethod = "GET")
	@RequestMapping(value = "/queryCount", method = {RequestMethod.GET, RequestMethod.POST})
	public ResponseEntity<Integer> queryCount(@ModelAttribute@Valid DspDbScanResultQueryForm form) throws BusinessServiceException {
		DspDbScanResultCondition condition = this.getConditionByQueryForm(form);
		int count = dspDbScanResultService.queryCount(condition);
		return getSuccessResult(count);
	}

	@ApiOperation(value = "查询敏感字段扫描结果表列表",notes = "查询敏感字段扫描结果表列表",httpMethod = "GET")
	@RequestMapping(value = "/queryList", method = {RequestMethod.GET, RequestMethod.POST})
	public ResponseEntity<CentreListResponse<DspDbScanResultVo>> queryList(@ModelAttribute@Valid DspDbScanResultQueryForm form) throws BusinessServiceException {
		DspDbScanResultCondition condition = this.getConditionByQueryForm(form);
		List<DspDbScanResultPo> poList = dspDbScanResultService.queryList(condition);
		List<DspDbScanResultVo> voList = CopyUtil.transfer(poList, DspDbScanResultVo.class);
		return getSuccessResult(getListResponse(voList));
	}

	@ApiOperation(value = "查询敏感字段扫描结果表列表(带分页)",notes = "查询敏感字段扫描结果表列表(带分页)",httpMethod = "GET")
	@RequestMapping(value = "/queryPageList", method = {RequestMethod.GET, RequestMethod.POST})
	public ResponseEntity<CentreCutPageResponse<DspDbScanResultVo>> queryPageList(@ModelAttribute@Valid DspDbScanResultQueryForm form) throws BusinessServiceException {
		DspDbScanResultCondition condition = this.getConditionByQueryForm(form);
		List<DspDbScanResultVo> voList = new ArrayList<>();
		int count = dspDbScanResultService.queryCount(condition);
		if (count > 0) {
			List<DspDbScanResultPo> poList = dspDbScanResultService.queryList(condition);
			voList = CopyUtil.transfer(poList, DspDbScanResultVo.class);
		}
		return getSuccessResult(getPageResponse(form, count, voList));
	}

	@ApiOperation(value = "新增敏感字段扫描结果表",notes = "新增敏感字段扫描结果表",httpMethod = "POST")
	@RequestMapping(value = "/add", method = {RequestMethod.GET, RequestMethod.POST})
	public ResponseEntity<DspDbScanResultVo> add(@ModelAttribute@Valid DspDbScanResultCreateForm form) throws BusinessServiceException {
		DspDbScanResultPo po = CopyUtil.transfer(form, DspDbScanResultPo.class);
		dspDbScanResultService.insert(po);
		DspDbScanResultVo vo = CopyUtil.transfer(po, DspDbScanResultVo.class);
		return getSuccessResult(vo);
	}

	@ApiOperation(value = "修改敏感字段扫描结果表",notes = "修改敏感字段扫描结果表",httpMethod = "POST")
	@RequestMapping(value = "/update", method = {RequestMethod.GET, RequestMethod.POST})
	public ResponseEntity update(@ModelAttribute@Valid DspDbScanResultUpdateForm form) throws BusinessServiceException {
		DspDbScanResultPo po = CopyUtil.transfer(form, DspDbScanResultPo.class);
		dspDbScanResultService.update(po);
		return getSuccessResult();
	}

	@ApiOperation(value = "删除敏感字段扫描结果表",notes = "删除敏感字段扫描结果表",httpMethod = "POST")
	@RequestMapping(value = "/delete", method = {RequestMethod.GET, RequestMethod.POST})
	public ResponseEntity delete(@ApiParam(value = "id", required = true)@RequestParam Integer scanResultId) throws BusinessServiceException {
		dspDbScanResultService.delete(scanResultId);
		return getSuccessResult();
	}

	/**
	 * DspDbScanResultQueryForm转换为DspDbScanResultCondition
	 *
	 * @param form
	 * @return
	 */
	private DspDbScanResultCondition getConditionByQueryForm(DspDbScanResultQueryForm form) {
		DspDbScanResultCondition condition = CopyUtil.transfer(form, DspDbScanResultCondition.class);
		return condition;
	}

}